package com.example.lianguisystem.common;

import com.example.lianguisystem.exceptionHandle.MyRuntimeException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class ExceptionAspect {

    private final String executeExpr = "execution(* com.example.lianguisystem.controller..*(..))";

    @AfterThrowing(value = executeExpr, throwing = "ex")
    public void newControllerExceptionHandle(Exception ex) {
        ex.printStackTrace();
        log.error("发生异常", ex);
        Class<? extends Exception> aClass = ex.getClass();
        String name = aClass.getName();
        throw new MyRuntimeException(name + "：" + ex.getMessage());
    }
}
